DEBUG = no
CC = gcc
RACINE = ../..
LIBPATH = -L $(RACINE)/lib/
LIB = $(RACINE)/lib/libthread.a
BIN = $(RACINE)/bin/performance/
EXEC = $(BIN)creationAttente $(BIN)chgContext $(BIN)destruction $(BIN)freedMemory $(BIN)test-priorite $(BIN)test-sans-semaphore $(BIN)test-avec-semaphore $(BIN)pereFils $(BIN)test-preemption $(BIN)test-mprotect

ifeq ($(DEBUG),yes)
	CFLAGS = -W -Wall -g
else
	CFLAGS = 
endif

LDFLAGS = -lpthread
LDFLAGSTH = $(LIBPATH) -lthread 

all: $(EXEC)

ifeq ($(DEBUG),yes)
	@echo "Génération en mode debug"
else
	@echo "Génération en mode release"
endif


$(BIN)test-avec-semaphore: test-avec-semaphore.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(CFLAGS)	
$(BIN)test-sans-semaphore: test-sans-semaphore.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(CFLAGS)	
$(BIN)test-mprotect: test-mprotect.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(CFLAGS)
$(BIN)pereFils: pereFils.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(CFLAGS)
$(BIN)test-preemption: test-preemption.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(CFLAGS)
$(BIN)test-priorite: test-priorite.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(LDFLAGS) $(CFLAGS)
$(BIN)creationAttente: creationAttente.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(LDFLAGS) $(CFLAGS)
$(BIN)chgContext: chgContext.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(LDFLAGS) $(CFLAGS)
$(BIN)destruction: destruction.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(LDFLAGS) $(CFLAGS)
$(BIN)freedMemory: freedMemory.c $(LIB)
	$(CC) -o $@ $< $(LDFLAGSTH) $(CFLAGS)

test-avec-semaphore: $(BIN)test-avec-semaphore
	./$<
test-sans-semaphore: $(BIN)test-sans-semaphore
	./$<
pereFils: $(BIN)pereFils
	./$<
test-mprotect: $(BIN)test-mprotect
	./$<
test-preemption: $(BIN)test-preemption
	./$<
test-priorite: $(BIN)test-priorite
	./$<
destruction: $(BIN)destruction
	./$<
chgContext: $(BIN)chgContext
	./$<
creationAttente: $(BIN)creationAttente
	./$<
freedMemory: $(BIN)freedMemory
	./$<

.PHONY: clean mrproper

clean:
	@rm *.o *~ *#

mrproper:
	@rm $(EXEC)